988D - Points and Powers of Two - CodeForces Solution


brute force math *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
 
#define ll long long
#define el "\n"
#define endl "\n"
#define len(s) s.length()
#define io freopen("input.inp", "r", stdin);freopen("output.out", "w", stdout);
 
using namespace std;
 
int main()
{    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin >> n;

    int a[n+1];
    map<int, int> f;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        f[a[i]] = 1;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int mask = 0; mask <= 31; mask++)
            if (f.find(a[i]-(1<<mask)) != f.end() && f.find(a[i]+(1<<mask)) != f.end())
            {
                cout << 3 << el;
                cout << a[i]-(1<<mask) << ' ' << a[i] << ' ' << a[i]+(1<<mask);
                return 0;
            }
    }

    for (int i = 1; i <= n; i++)
        for (int mask = 0; mask <= 31; mask++)
        {
            if (f.find(a[i]+(1<<mask)) != f.end())
            {
                cout << 2 << el;
                cout << a[i] << ' ' << a[i]+(1<<mask);
                return 0;
            }
        }

    cout << 1 << el;
    cout << a[1];
    return 0;
}


Comments

Submit
0 Comments
More Questions

1144D - Equalize Them All
298A - Snow Footprints
1753B - Factorial Divisibility
804A - Find Amir
1541C - Great Graphs
607B - Zuma
30A - Accounting
959C - Mahmoud and Ehab and the wrong algorithm
1215A - Yellow Cards
237B - Young Table
1216D - Swords
271D - Good Substrings
573A - Bear and Poker
10A - Power Consumption Calculation
1244B - Rooms and Staircases
777A - Shell Game
1698D - Fixed Point Guessing
415B - Mashmokh and Tokens
26D - Tickets
471B - MUH and Important Things
982B - Bus of Characters
1102B - Array K-Coloring
818A - Diplomas and Certificates
70A - Cookies
798A - Mike and palindrome
1690F - Shifting String
366B - Dima and To-do List
120B - Quiz League
740A - Alyona and copybooks
1491A - K-th Largest Value